package com.ktgj.other.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.EtDimProvince;
import com.ktgj.other.service.IEtDimProvinceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 省Controller
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/province")
public class EtDimProvinceController extends BaseController
{
    @Autowired
    private IEtDimProvinceService etDimProvinceService;

    /**
     * 查询省列表
     */
    @PreAuthorize(hasPermi = "other:province:list")
    @GetMapping("/list")
    public TableDataInfo list(EtDimProvince etDimProvince)
    {
        startPage();
        List<EtDimProvince> list = etDimProvinceService.selectEtDimProvinceList(etDimProvince);
        return getDataTable(list);
    }

    /**
     * 导出省列表
     */
    @PreAuthorize(hasPermi = "other:province:export")
    @Log(title = "省", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EtDimProvince etDimProvince) throws IOException
    {
        List<EtDimProvince> list = etDimProvinceService.selectEtDimProvinceList(etDimProvince);
        ExcelUtil<EtDimProvince> util = new ExcelUtil<EtDimProvince>(EtDimProvince.class);
        util.exportExcel(response, list, "省数据");
    }

    /**
     * 获取省详细信息
     */
    @PreAuthorize(hasPermi = "other:province:query")
    @GetMapping(value = "/{provinceid}")
    public AjaxResult getInfo(@PathVariable("provinceid") Long provinceid)
    {
        return AjaxResult.success(etDimProvinceService.selectEtDimProvinceById(provinceid));
    }

    /**
     * 新增省
     */
    @PreAuthorize(hasPermi = "other:province:add")
    @Log(title = "省", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EtDimProvince etDimProvince)
    {
        return toAjax(etDimProvinceService.insertEtDimProvince(etDimProvince));
    }

    /**
     * 修改省
     */
    @PreAuthorize(hasPermi = "other:province:edit")
    @Log(title = "省", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EtDimProvince etDimProvince)
    {
        return toAjax(etDimProvinceService.updateEtDimProvince(etDimProvince));
    }

    /**
     * 删除省
     */
    @PreAuthorize(hasPermi = "other:province:remove")
    @Log(title = "省", businessType = BusinessType.DELETE)
	@DeleteMapping("/{provinceids}")
    public AjaxResult remove(@PathVariable Long[] provinceids)
    {
        return toAjax(etDimProvinceService.deleteEtDimProvinceByIds(provinceids));
    }
}
